﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiFLEXCableSettingsWindow
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Flexibles;
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Markup;
using System.Windows.Media;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands;

public class CUiFLEXCableSettingsWindow : TxWindow, IComponentConnector
{
  private CUiFLEXCableSettingsCmd m_command;
  private const string CABLE_CONSTRAINT_COLORS_CHOICE = "cableConstraintColorsChoice";
  private CApFLEXSettingsData m_cableSettingsData = new CApFLEXSettingsData();
  internal CUiFLEXCableSettingsWindow dMainDialog;
  internal RowDefinition ObstacleRow;
  internal RowDefinition GravityRow;
  internal System.Windows.Controls.CheckBox doesCablesConsiderObstaclesCkBox;
  internal System.Windows.Controls.Image m_motionInfo;
  internal Grid GravityDirectionGrid;
  internal TextBlock GravityDirectionTextBlock;
  internal System.Windows.Controls.ComboBox TxObjectComboBoxGravityDirection;
  internal RowDefinition EnhanceDisplayRow;
  internal RowDefinition DisplayTwistLinesRow;
  internal RowDefinition ConstraintColorsTypeRow;
  internal System.Windows.Controls.CheckBox enhancedDisplayCkBox;
  internal System.Windows.Controls.CheckBox displayTwistLinesOnCablesCkBox;
  internal Grid constraintColorsTypeGrid;
  internal System.Windows.Controls.CheckBox constraintColorsTypeCkBox;
  internal System.Windows.Controls.ComboBox TxObjectComboBoxConstraintColorsType;
  internal System.Windows.Controls.Image m_displayInfo;
  internal TextBlock constraintColorsToolTip;
  internal System.Windows.Controls.Button btnOk;
  internal System.Windows.Controls.Button btnClose;
  private bool _contentLoaded;

  public CUiFLEXCableSettingsWindow(CUiFLEXCableSettingsCmd command)
  {
    this.m_command = command;
    this.InitializeComponent();
    this.LoadStorageData();
    this.m_motionInfo.Source = TxImageManager.GetImageByKey("InfoColor").ConvertTo<ImageSource>(new System.Drawing.Size());
    this.m_displayInfo.Source = TxImageManager.GetImageByKey("InfoColor").ConvertTo<ImageSource>(new System.Drawing.Size());
  }

  public bool ConsiderAllPartsAsObstacles
  {
    get => this.m_cableSettingsData.ConsiderAllPartsAsObstacles;
    set => this.m_cableSettingsData.ConsiderAllPartsAsObstacles = value;
  }

  public TxCableSettings.TxCableGravityDirection GravityDirection
  {
    get => this.m_cableSettingsData.GravityDirection;
    set => this.m_cableSettingsData.GravityDirection = value;
  }

  public bool SmoothCableDisplay
  {
    get => this.m_cableSettingsData.SmoothCableDisplay;
    set => this.m_cableSettingsData.SmoothCableDisplay = value;
  }

  public bool TwistLinesOnCables
  {
    get => this.m_cableSettingsData.TwistLinesOnCables;
    set => this.m_cableSettingsData.TwistLinesOnCables = value;
  }

  public TxCableSettings.TxCableConstraintColorsType ConstraintColorsType
  {
    get => this.m_cableSettingsData.ConstraintColorsType;
    set => this.m_cableSettingsData.ConstraintColorsType = value;
  }

  public int GravityDirectionIndex
  {
    get => (int) this.GravityDirection;
    set => this.GravityDirection = (TxCableSettings.TxCableGravityDirection) value;
  }

  public int ConstraintColorsTypeIndex
  {
    get
    {
      int constraintColorsTypeIndex = 0;
      if (this.ConstraintColorsType != null)
        constraintColorsTypeIndex = this.ConstraintColorsType - 1;
      return constraintColorsTypeIndex;
    }
  }

  public bool IsConstraintColoringActivated
  {
    get => this.ConstraintColorsType > 0;
    set
    {
      if (value)
        this.ConstraintColorsType = (TxCableSettings.TxCableConstraintColorsType) (this.TxObjectComboBoxConstraintColorsType.SelectedIndex + 1);
      else
        this.ConstraintColorsType = (TxCableSettings.TxCableConstraintColorsType) 0;
    }
  }

  private void TxWindow_Loaded(object sender, RoutedEventArgs e)
  {
  }

  private void TxWindow_Closed(object sender, RoutedEventArgs e)
  {
  }

  private void btnOk_Click(object sender, RoutedEventArgs e)
  {
    Cursor current = Cursor.Current;
    try
    {
      Cursor.Current = Cursors.WaitCursor;
      this.m_cableSettingsData.ApplyCableSettings();
      TxApplication.RefreshDisplay();
      this.SaveStorageData();
      Cursor.Current = current;
      ((Window) this).Close();
    }
    catch (Exception ex)
    {
      Cursor.Current = current;
      int num = (int) TxMessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
  }

  private void btnCancel_Click(object sender, RoutedEventArgs e) => ((Window) this).Close();

  private void OnConstraintColoringActivated(object sender, RoutedEventArgs e)
  {
    this.TxObjectComboBoxConstraintColorsType.IsEnabled = true;
  }

  private void OnConstraintColoringDeactivated(object sender, RoutedEventArgs e)
  {
    this.TxObjectComboBoxConstraintColorsType.IsEnabled = false;
  }

  private void OnGravityDirectionChanged(object sender, SelectionChangedEventArgs e)
  {
    this.GravityDirection = (TxCableSettings.TxCableGravityDirection) (sender as System.Windows.Controls.ComboBox).SelectedIndex;
  }

  private void OnConstraintColorsTypeChanged(object sender, SelectionChangedEventArgs e)
  {
    TxCableSettings.TxCableConstraintColorsType constraintColorsType = (TxCableSettings.TxCableConstraintColorsType) ((sender as System.Windows.Controls.ComboBox).SelectedIndex + 1);
    this.ChangeConstraintColorsToolTip(constraintColorsType);
    this.UpdateConstraintColorsType(constraintColorsType);
  }

  private void ChangeConstraintColorsToolTip(
    TxCableSettings.TxCableConstraintColorsType constraintColorsType)
  {
    if (constraintColorsType != 1)
    {
      if (constraintColorsType != 2)
        return;
      this.constraintColorsToolTip.Text = CApFLEXStringTable.ToolTipContactForceColors;
    }
    else
      this.constraintColorsToolTip.Text = CApFLEXStringTable.ToolTipTwistColors;
  }

  private void UpdateConstraintColorsType(
    TxCableSettings.TxCableConstraintColorsType constraintColorsType)
  {
    if (this.IsConstraintColoringActivated)
      this.ConstraintColorsType = constraintColorsType;
    else
      this.ConstraintColorsType = (TxCableSettings.TxCableConstraintColorsType) 0;
  }

  private void SaveStorageData()
  {
    TxCommandPrivateDataStorage privateDataStorage = new TxCommandPrivateDataStorage((ITxCommand) this.m_command);
    try
    {
      privateDataStorage.SetIntValue("cableConstraintColorsChoice", this.TxObjectComboBoxConstraintColorsType.SelectedIndex);
    }
    catch (Exception ex)
    {
      string message = ex.Message;
    }
  }

  private void LoadStorageData()
  {
    int? nullable = this.LoadRegistryIntValue(new TxCommandPrivateDataStorage((ITxCommand) this.m_command), "cableConstraintColorsChoice");
    if (!nullable.HasValue)
      return;
    this.TxObjectComboBoxConstraintColorsType.SelectedIndex = nullable.Value;
  }

  private int? LoadRegistryIntValue(TxCommandPrivateDataStorage storage, string valueName)
  {
    int? nullable1 = new int?();
    int? nullable2;
    try
    {
      nullable2 = new int?(storage.GetIntValue(valueName));
    }
    catch (TxCommandPrivateDataValueNotStoredException ex)
    {
      nullable2 = new int?();
    }
    return nullable2;
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    System.Windows.Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/flexibles/windows/cuiflexcablesettingswindow.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        this.dMainDialog = (CUiFLEXCableSettingsWindow) target;
        break;
      case 2:
        this.ObstacleRow = (RowDefinition) target;
        break;
      case 3:
        this.GravityRow = (RowDefinition) target;
        break;
      case 4:
        this.doesCablesConsiderObstaclesCkBox = (System.Windows.Controls.CheckBox) target;
        break;
      case 5:
        this.m_motionInfo = (System.Windows.Controls.Image) target;
        break;
      case 6:
        this.GravityDirectionGrid = (Grid) target;
        break;
      case 7:
        this.GravityDirectionTextBlock = (TextBlock) target;
        break;
      case 8:
        this.TxObjectComboBoxGravityDirection = (System.Windows.Controls.ComboBox) target;
        break;
      case 9:
        this.EnhanceDisplayRow = (RowDefinition) target;
        break;
      case 10:
        this.DisplayTwistLinesRow = (RowDefinition) target;
        break;
      case 11:
        this.ConstraintColorsTypeRow = (RowDefinition) target;
        break;
      case 12:
        this.enhancedDisplayCkBox = (System.Windows.Controls.CheckBox) target;
        break;
      case 13:
        this.displayTwistLinesOnCablesCkBox = (System.Windows.Controls.CheckBox) target;
        break;
      case 14:
        this.constraintColorsTypeGrid = (Grid) target;
        break;
      case 15:
        this.constraintColorsTypeCkBox = (System.Windows.Controls.CheckBox) target;
        this.constraintColorsTypeCkBox.Checked += new RoutedEventHandler(this.OnConstraintColoringActivated);
        this.constraintColorsTypeCkBox.Unchecked += new RoutedEventHandler(this.OnConstraintColoringDeactivated);
        break;
      case 16 /*0x10*/:
        this.TxObjectComboBoxConstraintColorsType = (System.Windows.Controls.ComboBox) target;
        this.TxObjectComboBoxConstraintColorsType.SelectionChanged += new SelectionChangedEventHandler(this.OnConstraintColorsTypeChanged);
        break;
      case 17:
        this.m_displayInfo = (System.Windows.Controls.Image) target;
        break;
      case 18:
        this.constraintColorsToolTip = (TextBlock) target;
        break;
      case 19:
        this.btnOk = (System.Windows.Controls.Button) target;
        this.btnOk.Click += new RoutedEventHandler(this.btnOk_Click);
        break;
      case 20:
        this.btnClose = (System.Windows.Controls.Button) target;
        this.btnClose.Click += new RoutedEventHandler(this.btnCancel_Click);
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
